/**
 * Zero
 *
 * @author Darksiderl
 * @date 2018/2/27
 *
 * 二维数组置零
 */
public class Zero {

    public static void main(String[] args) {

        int[][] a = {{0, 1, 3}, {1, 3, 1}, {0, 3, 1}};
        printL(a);
        setZero(a);
        printL(a);
    }

    private static void printL(int[][] a) {
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[0].length; j++) {
                if (j == a[0].length - 1) {
                    System.out.println(a[i][j]);
                } else {
                    System.out.print(a[i][j]);
                }
            }
        }
    }

    public static void setZero(int[][] origin) {
        //行
        int rowLength = origin.length;
        //列
        int colLength = origin[0].length;

        for (int i = 0; i < rowLength; i++) {

            for (int j = 0; j < colLength; j++) {

                if (origin[i][j] == 0) {
                    for (int k = 0; k < rowLength; k++) {
                        if (origin[i][k] != 0) {
                            origin[i][k] = '*';
                        }
                    }

                    for (int k = 0; k < colLength; k++) {
                        if (origin[k][j] != 0) {
                            origin[k][j] = '*';
                        }
                    }
                }

            }
        }


        for (int i = 0; i < rowLength; i++) {
            for (int j = 0; j < colLength; j++) {
                if (origin[i][j] == '*') {
                    origin[i][j] = 0;
                }
            }
        }

    }

}
